package edu.zzu.servideImpl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.zzu.Entity.Message;
import edu.zzu.dao.MessageDao;
import edu.zzu.daoImpl.MessageDaoImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MessageService implements edu.zzu.service.MessageService {

    @Autowired
    private MessageDao messageDao;

    @Autowired
    private ObjectMapper jsonMapper;

    @Override
    public String getMessageByUserId(Long id) {

        try {
            return jsonMapper.writeValueAsString(messageDao.getMessageByUserId(id));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    public String getMessageByTel(String tel) {
        try {
            return jsonMapper.writeValueAsString(messageDao.getMessageByTel(tel));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
